package sgpt.Beans.DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import com.sun.imageio.plugins.common.PaletteBuilder;

import sgpt.Beans.DAO.interfaces.*;
import sgpt.comentario.ComentarioDAO;
import sgpt.comentario.IcomentarioDAO;
import sgpt.passeio.CompraPasseioDAO;
import sgpt.passeio.IcompraPasseioDAO;
import sgpt.passeio.IpasseioDAO;
import sgpt.passeio.PasseioDAO;

public class JdbcDaoFactory implements DAOFactory {

	private static JdbcDaoFactory JdbcDaoFactoryInst;
	private IpasseioDAO PasseioDAOInst;
	private IcidadeDAO CidadeDAOInst;
	private IplanoDAO PlanoDAOInst;
	private IcomentarioDAO ComentarioDAOInst;
	private IclienteDAO clienteDAOInst;
	private IhospedagemDAO hospedagemDAOInst;
	private IperfilDAO perfilDAOInst;
	private ItransladoDAO transladoDAOInst;
	private ItransporteDAO transporteDAOInst;
	private IcompraPasseioDAO compraPasseioDAOInst;
	private IenderecoDAO EnderecoDAOInst;
	private Connection conn=null;
    public Statement stmt=null;
	private IetapaDAO EtapaDAOInst;
    
    public static String database="sgpturismo.db";
    
	public static synchronized JdbcDaoFactory getInstance(){
		if (JdbcDaoFactoryInst == null){
			JdbcDaoFactoryInst = new JdbcDaoFactory(database);
		}
		return JdbcDaoFactoryInst;
	}
	
	public JdbcDaoFactory(String datafile) {
		super();
		JdbcSqliteConnection(datafile);  
	}

	/**
	 * Faz a conexao com o banco de dados sqlite
	 * @param datafile
	 */
	public void JdbcSqliteConnection(String datafile) {
	    	String dbPath=JdbcDaoFactory.class.getResource(datafile).getPath();
	           String url = "jdbc:sqlite:"+dbPath;
	           System.out.println(dbPath);
	       try {
	    	   Class.forName("org.sqlite.JDBC").newInstance();
	           conn = DriverManager.getConnection(url);

	       }
	       catch(Exception e){
	    	  e.printStackTrace();
	          System.out.println("**************Problemas ao conectar com o Driver JBDC.");
	          System.out.println(dbPath);
	       }
	    }

	public synchronized IclienteDAO getClienteDAO() {
		if (clienteDAOInst == null) clienteDAOInst = new ClienteDAO(conn);
		return clienteDAOInst;
	}

	public synchronized IcomentarioDAO getComentarioDAO() {
		if (ComentarioDAOInst == null) ComentarioDAOInst = new ComentarioDAO(conn);
		return ComentarioDAOInst;
	}

	public synchronized IhospedagemDAO getHospedagemDAO() {
		if (hospedagemDAOInst==null) hospedagemDAOInst = new HospedagemDAO(conn);
		return hospedagemDAOInst;
	}

	public synchronized IpasseioDAO getPasseioDAO() {
		if (PasseioDAOInst==null){
			PasseioDAOInst = new PasseioDAO(conn);
		}
		
		return PasseioDAOInst;
	}
	
	public synchronized IcompraPasseioDAO getCompraPasseioDAO() {
		if (compraPasseioDAOInst==null){
			compraPasseioDAOInst = new CompraPasseioDAO(conn);
		}
		
		return compraPasseioDAOInst;
	}

	public synchronized IperfilDAO getPerfilDAO() {
		if (perfilDAOInst == null){
			perfilDAOInst = new PerfilDAO(conn);
		}
		return perfilDAOInst;
	}

	public synchronized IplanoDAO getPlanoDAO() {
		if (PlanoDAOInst == null) PlanoDAOInst = new PlanoDAO(conn);
		return PlanoDAOInst;
	}

	public synchronized ItransladoDAO getTransladoDAO() {
		if (transladoDAOInst==null) transladoDAOInst = new TransladoDAO(conn);
		return transladoDAOInst;
	}

	public synchronized ItransporteDAO getTransporteDAO() {
		if (transporteDAOInst==null) transporteDAOInst = new TransporteDAO(conn);
		return transporteDAOInst;
	}

	public synchronized IcidadeDAO getCidadeDAO() {
		if (CidadeDAOInst==null){
			CidadeDAOInst = new CidadeDAO(conn);
		}
		return CidadeDAOInst;
	}
	
	public synchronized IenderecoDAO getEnderecoDAO() {
		if (EnderecoDAOInst == null) EnderecoDAOInst = new EnderecoDAO(conn);
		return EnderecoDAOInst;
	}

	public synchronized IetapaDAO getEtapaDAO() {
		if (EtapaDAOInst == null) EtapaDAOInst = new EtapaDAO(conn);
		return EtapaDAOInst;
	}
 
}
 
